/**
 * Date Modified: $Date: 2009-08-28 10:39:55 +1000 (Fri, 28 Aug 2009) $
 * Version: $Revision: 129 $
 * 
 * Copyright 2008 The Australian National University (ANU)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
//package org.ands.rifcs.example;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.*;

import javax.xml.parsers.ParserConfigurationException;


import org.ands.rifcs.base.*;

import org.xml.sax.SAXException;

public class Hospital
{
	private static RIFCS rifcs = null;

    public static void main(String[] args) throws RIFCSException, FileNotFoundException, SAXException, ParserConfigurationException, IOException
    {
        RIFCSWrapper mw = new RIFCSWrapper();
        rifcs = mw.getRIFCSObject();

        String[][] hospitals = {
        /*key*/  { 				"http://www.alfredhealth.org.au/Page.aspx?ID=23",
        /*namePart*/			"Alfred Hospital",
        /*url*/  				"http://www.alfredhealth.org.au/Page.aspx?ID=23 ",
        /*disease group rel*/ 	"http://www.biogrid.org.au/wps/portal/!ut/p/c5/04_SB8K8xLLM9MSSzPy8xBz9CP0os3iLQAsjQ28TA0sLNydXA6OwYM8wiyBzYzMPE_1wkA7cKgzNIfIGOICjgb6fR35uqn6kfpQ5TlMsTfQjc1LTE5Mr9Quys9Oc0xUVAU--968!/dl3/d3/L0lJSklna21BL0lKakFBTXlBQkVSQ0pBISEvNEZHZ3NvMFZ2emE5SUFnIS83XzhRO",
        		 }
        
        };
        
        for(int i=0; i<hospitals.length;i++){
        	
        	RegistryObject r = rifcs.newRegistryObject();
         
            //variable
        	r.setKey(hospitals[i][0]);
            //r.setKey("http://www.alfredhealth.org.au/Page.aspx?ID=23");
            r.setGroup("BioGrid");
            r.setOriginatingSource("https://services.ands.org.au/sandbox/orca");
            
            Party par = r.newParty();
            par.setType("group");
            Name n1 = par.newName();
            //variable
            n1.addNamePart(hospitals[i][1],"title");
            //n1.addNamePart("Alfred Hospital", "title");
            par.addName(n1);
            
            Location loc = par.newLocation();
            Address add = loc.newAddress();
            Electronic elec = add.newElectronic();
            elec.setType("url");
            //variable
            elec.setValue(hospitals[i][2]);
            //elec.setValue("http://www.alfredhealth.org.au/Page.aspx?ID=23 ");
            add.addElectronic(elec);
            loc.addAddress(add);
            par.addLocation(loc);
            
            //disease group relation
            String collectors[] = hospitals[i][3].split(",");
            for(int m=0;m<collectors.length;m++){
            	RelatedObject relObj = par.newRelatedObject();
                //variable
                relObj.setKey(collectors[m]);
                //relObj.setKey("http://www.biogrid.org.au/wps/portal/!ut/p/c5/04_SB8K8xLLM9MSSzPy8xBz9CP0os3iLQAsjQ28TA0sLNydXA6OwYM8wiyBzYzMPE_1wkA7cKgzNIfIGOICjgb6fR35uqn6kfpQ5TlMsTfQjc1LTE5Mr9Quys9Oc0xUVAU--968!/dl3/d3/L0lJSklna21BL0lKakFBTXlBQkVSQ0pBISEvNEZHZ3NvMFZ2emE5SUFnIS83XzhRO");
                relObj.addRelation("isCollectorOf", null, null, null);
                par.addRelatedObject(relObj);
            }
            
    
            RelatedObject relObj3 = par.newRelatedObject();
            relObj3.setKey("www.biogrid.gov.au");
            relObj3.addRelation("isParticipantIn", null, null, null);
            par.addRelatedObject(relObj3);
            
     
            r.addParty(par);
            rifcs.addRegistryObject(r);
        }
       
	    mw.validate();

	    FileOutputStream outputFile=null;
	    try{
	    	outputFile = new FileOutputStream("hospital2.xml");
	    	
	    }
	    catch(IOException e1){
	    	System.out.println("Error writing to hospital.xml");
	    }
	    
		//mw.write(System.out);
		mw.write(outputFile);
		System.out.println("Successfully written to XML file.");
    }
}